package devices

import (
	"context"
	"github.com/gogf/gf/v2/frame/g"
)

// CreateAeParamDataTable 声发射参数表创建
func (s *sDevice) CreateAeParamDataTable(ctx context.Context, dbConn string, table string) (err error) {
	db := g.DB(dbConn)
	sql := "CREATE TABLE IF NOT EXISTS `" + table + "` (" +
		"  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'id'," +
		" `device_no` varchar(60) NOT NULL DEFAULT '' COMMENT '设备编号'," +
		"  `ae_measure_speed` int(11) unsigned DEFAULT NULL COMMENT '采样速度'," +
		"  `ae_gain_value` int(11) unsigned DEFAULT NULL COMMENT '前放放大倍数'," +
		" `ae_enlarge_value` double DEFAULT NULL COMMENT '系统放大倍数'," +
		" `ae_amp` double DEFAULT NULL COMMENT '幅度'," +
		"  `ae_power` double DEFAULT NULL COMMENT '能量'," +
		"  `ae_asl` double DEFAULT NULL COMMENT '平均值'," +
		"  `ae_rms` double DEFAULT NULL COMMENT '有效值'," +
		"  `ae_ringing_num` int(11) unsigned DEFAULT NULL COMMENT '振铃计数'," +
		"  `ae_rising_num` int(11) unsigned DEFAULT NULL COMMENT '上升计数'," +
		"  `ae_rising_time` int(11) unsigned DEFAULT NULL COMMENT '上升时间'," +
		"  `ae_durning_time` int(11) unsigned DEFAULT NULL COMMENT '持续时间'," +
		" `ae_peak_freq` int(11) unsigned DEFAULT NULL COMMENT '峰值频率'," +
		" `ae_centroid_fre` int(11) unsigned DEFAULT NULL COMMENT '质心频率'," +
		" `ae_fre1_band_pro` int(11) unsigned DEFAULT NULL COMMENT '局部功率谱1占比'," +
		" `ae_fre2_band_pro` int(11) unsigned DEFAULT NULL COMMENT '局部功率谱2占比'," +
		" `ae_fre3_band_pro` int(11) unsigned DEFAULT NULL COMMENT '局部功率谱3占比'," +
		" `ae_fre4_band_pro` int(11) unsigned DEFAULT NULL COMMENT '局部功率谱4占比'," +
		" `ae_fre5_band_pro` int(11) unsigned DEFAULT NULL COMMENT '局部功率谱5占比'," +
		"  `created_at` datetime DEFAULT NULL COMMENT '创建时间'," +
		"  `status` tinyint(3) DEFAULT '0' COMMENT '状态'," +
		"  `sampletime` bigint(20) unsigned DEFAULT NULL COMMENT '采集时间', " +
		"  PRIMARY KEY (`id`) USING BTREE," +
		"  UNIQUE KEY `device_sampletime` (`sampletime`,`device_no`) USING BTREE " +
		") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=COMPACT COMMENT='声发射设备参数数据表';"
	_, err = db.Exec(ctx, sql)
	return
}

// DropAeParamTable 声发射参数表删除
func (s *sDevice) DropAeParamTable(ctx context.Context, dbConn string, table string) (err error) {
	db := g.DB(dbConn)
	sql := " DROP TABLE IF EXISTS " + table
	_, err = db.Exec(ctx, sql)
	return
}

// CreateVIParamDataTable  振动参数数据表创建
func (s *sDevice) CreateVIParamDataTable(ctx context.Context, dbConn string, table string) (err error) {
	db := g.DB(dbConn)
	sql := "CREATE TABLE IF NOT EXISTS `" + table + "` (" +
		"  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT," +
		"  `created_at` datetime DEFAULT NULL COMMENT '创建时间'," +
		"  `device_no` varchar(60) NOT NULL DEFAULT '' COMMENT 'sn'," +
		"  `vi_measure_type` smallint(6) unsigned DEFAULT NULL COMMENT '采样类型  0 单轴 1 三轴'," +
		"  `vi_measure_freq` int(10) unsigned DEFAULT NULL COMMENT '采样频率'," +
		"  `vi_max_acc_x` float DEFAULT NULL COMMENT 'x最大加速度'," +
		"  `vi_max_accfreq_x` float DEFAULT NULL COMMENT 'x最大加速度发生频率'," +
		"  `vi_acc_peak_x` float DEFAULT NULL COMMENT 'x加速度峰峰值'," +
		"  `vi_acc_average_x` float DEFAULT NULL COMMENT 'x加速度平均值'," +
		"  `vi_acc_abs_average_x` float DEFAULT NULL COMMENT 'x加速度整流平均值'," +
		"  `vi_acc_rms_x` float DEFAULT NULL COMMENT 'x加速度有效值'," +
		"  `vi_acc_var_x` float DEFAULT NULL COMMENT 'x加速度方差'," +
		"  `vi_acc_std_x` float DEFAULT NULL COMMENT 'x加速度标准差'," +
		"  `vi_acc_crest_x` float DEFAULT NULL COMMENT 'x加速度峰值因子'," +
		"  `vi_acc_pulse_x` float DEFAULT NULL COMMENT 'x加速度脉冲因子'," +
		"  `vi_acc_form_x` float DEFAULT NULL COMMENT 'x加速度波形因子'," +
		"  `vi_acc_allow_x` float DEFAULT NULL COMMENT 'x加速度裕度因子'," +
		"  `vi_acc_skew_x` float DEFAULT NULL COMMENT 'x加速度偏度因子'," +
		"  `vi_acc_kurtosis_x` float DEFAULT NULL COMMENT 'x加速度峭度因子'," +
		"  `vi_acc_average_freq_x` float DEFAULT NULL COMMENT 'x加速度平均频率'," +
		"  `vi_acc_centroid_freq_x` float DEFAULT NULL COMMENT 'x加速度质心频率'," +
		"  `vi_acc_rms_freq_x` float DEFAULT NULL COMMENT 'x加速度均方根频率'," +
		"  `vi_acc_ms_freq_x` float DEFAULT NULL COMMENT 'x加速度均方频率'," +
		"  `vi_acc_var_freq_x` float DEFAULT NULL COMMENT 'x加速度方差频率'," +
		"  `vi_acc_std_freq_x` float DEFAULT NULL COMMENT 'x加速度标准差频率'," +
		"  `vi_velocity_max_x` float DEFAULT NULL COMMENT 'x速度峰值单位m/s', " +
		" `vi_velocity_maxfreq_x` float DEFAULT NULL COMMENT 'x速度峰值频率 单位hz'," +
		"  `vi_velocity_rms_x` float DEFAULT NULL COMMENT 'x速度有效值'," +
		"  `vi_max_distance_x` float DEFAULT NULL COMMENT 'x最大距离值 单位mm'," +
		" `vi_angle_x` float DEFAULT NULL COMMENT 'x安装角度'," +
		"  `vi_max_acc_y` float DEFAULT NULL COMMENT 'y最大加速度'," +
		"  `vi_max_accfreq_y` float DEFAULT NULL COMMENT 'y最大加速度发生频率'," +
		"  `vi_acc_peak_y` float DEFAULT NULL COMMENT 'y加速度峰峰值'," +
		"  `vi_acc_average_y` float DEFAULT NULL COMMENT 'y加速度平均值'," +
		"  `vi_acc_abs_average_y` float DEFAULT NULL COMMENT 'y加速度整流平均值'," +
		"  `vi_acc_rms_y` float DEFAULT NULL COMMENT 'y加速度有效值'," +
		"  `vi_acc_var_y` float DEFAULT NULL COMMENT 'y加速度方差'," +
		"  `vi_acc_std_y` float DEFAULT NULL COMMENT 'y加速度标准差'," +
		"  `vi_acc_crest_y` float DEFAULT NULL COMMENT 'y加速度峰值因子'," +
		" `vi_acc_pulse_y` float DEFAULT NULL COMMENT 'y加速度脉冲因子'," +
		"  `vi_acc_form_y` float DEFAULT NULL COMMENT 'y加速度波形因子'," +
		"  `vi_acc_allow_y` float DEFAULT NULL COMMENT 'y加速度裕度因子'," +
		"  `vi_acc_skew_y` float DEFAULT NULL COMMENT 'y加速度偏度因子'," +
		"  `vi_acc_kurtosis_y` float DEFAULT NULL COMMENT 'y加速度峭度因子'," +
		"  `vi_acc_average_freq_y` float DEFAULT NULL COMMENT 'y加速度平均频率'," +
		"  `vi_acc_centroid_freq_y` float DEFAULT NULL COMMENT 'y加速度质心频率'," +
		" `vi_acc_rms_freq_y` float DEFAULT NULL COMMENT 'y加速度均方根频率'," +
		"  `vi_acc_ms_freq_y` float DEFAULT NULL COMMENT 'y加速度均方频率'," +
		"  `vi_acc_var_freq_y` float DEFAULT NULL COMMENT 'y加速度方差频率'," +
		"  `vi_acc_std_freq_y` float DEFAULT NULL COMMENT 'y加速度标准差频率'," +
		"  `vi_velocity_max_y` float DEFAULT NULL COMMENT 'y速度峰值单位m/s'," +
		"  `vi_velocity_maxfreq_y` float DEFAULT NULL COMMENT 'y速度峰值频率 单位hz'," +
		"  `vi_velocity_rms_y` float DEFAULT NULL COMMENT 'y速度有效值'," +
		"  `vi_max_distance_y` float DEFAULT NULL COMMENT 'y最大距离值 单位mm'," +
		"  `vi_angle_y` float DEFAULT NULL COMMENT 'y安装角度'," +
		"  `vi_max_acc_z` float DEFAULT NULL COMMENT 'z最大加速度'," +
		"  `vi_max_accfreq_z` float DEFAULT NULL COMMENT 'z最大加速度发生频率'," +
		"  `vi_acc_peak_z` float DEFAULT NULL COMMENT 'z加速度峰峰值'," +
		"  `vi_acc_average_z` float DEFAULT NULL COMMENT 'z加速度平均值'," +
		"  `vi_acc_abs_average_z` float DEFAULT NULL COMMENT 'z加速度整流平均值'," +
		"  `vi_acc_rms_z` float DEFAULT NULL COMMENT 'z加速度有效值'," +
		"  `vi_acc_var_z` float DEFAULT NULL COMMENT 'z加速度方差'," +
		"  `vi_acc_std_z` float DEFAULT NULL COMMENT 'z加速度标准差'," +
		"  `vi_acc_crest_z` float DEFAULT NULL COMMENT 'z加速度峰值因子'," +
		"  `vi_acc_pulse_z` float DEFAULT NULL COMMENT 'z加速度脉冲因子'," +
		" `vi_acc_form_z` float DEFAULT NULL COMMENT 'z加速度波形因子'," +
		"  `vi_acc_allow_z` float DEFAULT NULL COMMENT 'z加速度裕度因子'," +
		"  `vi_acc_skew_z` float DEFAULT NULL COMMENT 'z加速度偏度因子'," +
		"  `vi_acc_kurtosis_z` float DEFAULT NULL COMMENT 'z加速度峭度因子'," +
		"  `vi_acc_average_freq_z` float DEFAULT NULL COMMENT 'z加速度平均频率'," +
		"  `vi_acc_centroid_freq_z` float DEFAULT NULL COMMENT 'z加速度质心频率'," +
		"  `vi_acc_rms_freq_z` float DEFAULT NULL COMMENT 'z加速度均方根频率'," +
		"  `vi_acc_ms_freq_z` float DEFAULT NULL COMMENT 'z加速度均方频率'," +
		"  `vi_acc_var_freq_z` float DEFAULT NULL COMMENT 'z加速度方差频率'," +
		"  `vi_acc_std_freq_z` float DEFAULT NULL COMMENT 'z加速度标准差频率'," +
		"  `vi_velocity_max_z` float DEFAULT NULL COMMENT 'z速度峰值单位m/s'," +
		"  `vi_velocity_maxfreq_z` float DEFAULT NULL COMMENT 'z速度峰值频率 单位hz'," +
		"  `vi_velocity_rms_z` float DEFAULT NULL COMMENT 'z速度有效值'," +
		"  `vi_max_distance_z` float DEFAULT NULL COMMENT 'z最大距离值 单位mm'," +
		"  `vi_angle_z` float DEFAULT NULL COMMENT 'z安装角度'," +
		" `vi_temperature` float DEFAULT NULL COMMENT '温度'," +
		" `vi_voltage` float DEFAULT NULL COMMENT '电压'," +
		"   `status` tinyint DEFAULT NULL COMMENT '状态'," +
		"  `sampletime` bigint(20) unsigned DEFAULT NULL COMMENT 'sampletime'," +
		"  PRIMARY KEY (`id`) USING BTREE, UNIQUE KEY `device_sampletime` (`sampletime`,`device_no`) USING BTREE" +
		") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=COMPACT COMMENT='振动数据表';"
	_, err = db.Exec(ctx, sql)
	if err != nil {
		return err
	}
	return
}

// DropVIParamDataTable 振动参数数据表删除
func (s *sDevice) DropVIParamDataTable(ctx context.Context, dbConn string, table string) (err error) {
	db := g.DB(dbConn)
	sql := " DROP TABLE IF EXISTS " + table
	_, err = db.Exec(ctx, sql)
	return
}

// CreateAeVIParamDataTable  声发射和振动参数数据表创建
func (s *sDevice) CreateAeVIParamDataTable(ctx context.Context, dbConn string, table string) (err error) {
	db := g.DB(dbConn)
	sql := "CREATE TABLE IF NOT EXISTS `" + table + "` (" +
		"  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT," +
		"  `created_at` datetime DEFAULT NULL COMMENT '创建时间'," +
		"  `device_no` varchar(60) NOT NULL DEFAULT '' COMMENT 'sn'," +
		"  `ae_measure_speed` int(11) unsigned DEFAULT NULL COMMENT '采样速度'," +
		"  `ae_gain_value` int(11) unsigned DEFAULT NULL COMMENT '前放放大倍数'," +
		" `ae_enlarge_value` double DEFAULT NULL COMMENT '系统放大倍数'," +
		" `ae_amp` double DEFAULT NULL COMMENT '幅度'," +
		"  `ae_power` double DEFAULT NULL COMMENT '能量'," +
		"  `ae_asl` double DEFAULT NULL COMMENT '平均值'," +
		"  `ae_rms` double DEFAULT NULL COMMENT '有效值'," +
		"  `ae_ringing_num` int(11) unsigned DEFAULT NULL COMMENT '振铃计数'," +
		"  `ae_rising_num` int(11) unsigned DEFAULT NULL COMMENT '上升计数'," +
		"  `ae_rising_time` int(11) unsigned DEFAULT NULL COMMENT '上升时间'," +
		"  `ae_durning_time` int(11) unsigned DEFAULT NULL COMMENT '持续时间'," +
		" `ae_peak_freq` int(11) unsigned DEFAULT NULL COMMENT '峰值频率'," +
		" `ae_centroid_fre` int(11) unsigned DEFAULT NULL COMMENT '质心频率'," +
		" `ae_fre1_band_pro` int(11) unsigned DEFAULT NULL COMMENT '局部功率谱1占比'," +
		" `ae_fre2_band_pro` int(11) unsigned DEFAULT NULL COMMENT '局部功率谱2占比'," +
		" `ae_fre3_band_pro` int(11) unsigned DEFAULT NULL COMMENT '局部功率谱3占比'," +
		" `ae_fre4_band_pro` int(11) unsigned DEFAULT NULL COMMENT '局部功率谱4占比'," +
		" `ae_fre5_band_pro` int(11) unsigned DEFAULT NULL COMMENT '局部功率谱5占比'," +
		"  `vi_measure_type` smallint(6) unsigned DEFAULT NULL COMMENT '采样类型  0 单轴 1 三轴'," +
		"  `vi_measure_freq` int(10) unsigned DEFAULT NULL COMMENT '采样频率'," +
		"  `vi_max_acc_x` float DEFAULT NULL COMMENT 'x最大加速度'," +
		"  `vi_max_accfreq_x` float DEFAULT NULL COMMENT 'x最大加速度发生频率'," +
		"  `vi_acc_peak_x` float DEFAULT NULL COMMENT 'x加速度峰峰值'," +
		"  `vi_acc_average_x` float DEFAULT NULL COMMENT 'x加速度平均值'," +
		"  `vi_acc_abs_average_x` float DEFAULT NULL COMMENT 'x加速度整流平均值'," +
		"  `vi_acc_rms_x` float DEFAULT NULL COMMENT 'x加速度有效值'," +
		"  `vi_acc_var_x` float DEFAULT NULL COMMENT 'x加速度方差'," +
		"  `vi_acc_std_x` float DEFAULT NULL COMMENT 'x加速度标准差'," +
		"  `vi_acc_crest_x` float DEFAULT NULL COMMENT 'x加速度峰值因子'," +
		"  `vi_acc_pulse_x` float DEFAULT NULL COMMENT 'x加速度脉冲因子'," +
		"  `vi_acc_form_x` float DEFAULT NULL COMMENT 'x加速度波形因子'," +
		"  `vi_acc_allow_x` float DEFAULT NULL COMMENT 'x加速度裕度因子'," +
		"  `vi_acc_skew_x` float DEFAULT NULL COMMENT 'x加速度偏度因子'," +
		"  `vi_acc_kurtosis_x` float DEFAULT NULL COMMENT 'x加速度峭度因子'," +
		"  `vi_acc_average_freq_x` float DEFAULT NULL COMMENT 'x加速度平均频率'," +
		"  `vi_acc_centroid_freq_x` float DEFAULT NULL COMMENT 'x加速度质心频率'," +
		"  `vi_acc_rms_freq_x` float DEFAULT NULL COMMENT 'x加速度均方根频率'," +
		"  `vi_acc_ms_freq_x` float DEFAULT NULL COMMENT 'x加速度均方频率'," +
		"  `vi_acc_var_freq_x` float DEFAULT NULL COMMENT 'x加速度方差频率'," +
		"  `vi_acc_std_freq_x` float DEFAULT NULL COMMENT 'x加速度标准差频率'," +
		"  `vi_velocity_max_x` float DEFAULT NULL COMMENT 'x速度峰值单位m/s', " +
		" `vi_velocity_maxfreq_x` float DEFAULT NULL COMMENT 'x速度峰值频率 单位hz'," +
		"  `vi_velocity_rms_x` float DEFAULT NULL COMMENT 'x速度有效值'," +
		"  `vi_max_distance_x` float DEFAULT NULL COMMENT 'x最大距离值 单位mm'," +
		" `vi_angle_x` float DEFAULT NULL COMMENT 'x安装角度'," +
		"  `vi_max_acc_y` float DEFAULT NULL COMMENT 'y最大加速度'," +
		"  `vi_max_accfreq_y` float DEFAULT NULL COMMENT 'y最大加速度发生频率'," +
		"  `vi_acc_peak_y` float DEFAULT NULL COMMENT 'y加速度峰峰值'," +
		"  `vi_acc_average_y` float DEFAULT NULL COMMENT 'y加速度平均值'," +
		"  `vi_acc_abs_average_y` float DEFAULT NULL COMMENT 'y加速度整流平均值'," +
		"  `vi_acc_rms_y` float DEFAULT NULL COMMENT 'y加速度有效值'," +
		"  `vi_acc_var_y` float DEFAULT NULL COMMENT 'y加速度方差'," +
		"  `vi_acc_std_y` float DEFAULT NULL COMMENT 'y加速度标准差'," +
		"  `vi_acc_crest_y` float DEFAULT NULL COMMENT 'y加速度峰值因子'," +
		" `vi_acc_pulse_y` float DEFAULT NULL COMMENT 'y加速度脉冲因子'," +
		"  `vi_acc_form_y` float DEFAULT NULL COMMENT 'y加速度波形因子'," +
		"  `vi_acc_allow_y` float DEFAULT NULL COMMENT 'y加速度裕度因子'," +
		"  `vi_acc_skew_y` float DEFAULT NULL COMMENT 'y加速度偏度因子'," +
		"  `vi_acc_kurtosis_y` float DEFAULT NULL COMMENT 'y加速度峭度因子'," +
		"  `vi_acc_average_freq_y` float DEFAULT NULL COMMENT 'y加速度平均频率'," +
		"  `vi_acc_centroid_freq_y` float DEFAULT NULL COMMENT 'y加速度质心频率'," +
		" `vi_acc_rms_freq_y` float DEFAULT NULL COMMENT 'y加速度均方根频率'," +
		"  `vi_acc_ms_freq_y` float DEFAULT NULL COMMENT 'y加速度均方频率'," +
		"  `vi_acc_var_freq_y` float DEFAULT NULL COMMENT 'y加速度方差频率'," +
		"  `vi_acc_std_freq_y` float DEFAULT NULL COMMENT 'y加速度标准差频率'," +
		"  `vi_velocity_max_y` float DEFAULT NULL COMMENT 'y速度峰值单位m/s'," +
		"  `vi_velocity_maxfreq_y` float DEFAULT NULL COMMENT 'y速度峰值频率 单位hz'," +
		"  `vi_velocity_rms_y` float DEFAULT NULL COMMENT 'y速度有效值'," +
		"  `vi_max_distance_y` float DEFAULT NULL COMMENT 'y最大距离值 单位mm'," +
		"  `vi_angle_y` float DEFAULT NULL COMMENT 'y安装角度'," +
		"  `vi_max_acc_z` float DEFAULT NULL COMMENT 'z最大加速度'," +
		"  `vi_max_accfreq_z` float DEFAULT NULL COMMENT 'z最大加速度发生频率'," +
		"  `vi_acc_peak_z` float DEFAULT NULL COMMENT 'z加速度峰峰值'," +
		"  `vi_acc_average_z` float DEFAULT NULL COMMENT 'z加速度平均值'," +
		"  `vi_acc_abs_average_z` float DEFAULT NULL COMMENT 'z加速度整流平均值'," +
		"  `vi_acc_rms_z` float DEFAULT NULL COMMENT 'z加速度有效值'," +
		"  `vi_acc_var_z` float DEFAULT NULL COMMENT 'z加速度方差'," +
		"  `vi_acc_std_z` float DEFAULT NULL COMMENT 'z加速度标准差'," +
		"  `vi_acc_crest_z` float DEFAULT NULL COMMENT 'z加速度峰值因子'," +
		"  `vi_acc_pulse_z` float DEFAULT NULL COMMENT 'z加速度脉冲因子'," +
		" `vi_acc_form_z` float DEFAULT NULL COMMENT 'z加速度波形因子'," +
		"  `vi_acc_allow_z` float DEFAULT NULL COMMENT 'z加速度裕度因子'," +
		"  `vi_acc_skew_z` float DEFAULT NULL COMMENT 'z加速度偏度因子'," +
		"  `vi_acc_kurtosis_z` float DEFAULT NULL COMMENT 'z加速度峭度因子'," +
		"  `vi_acc_average_freq_z` float DEFAULT NULL COMMENT 'z加速度平均频率'," +
		"  `vi_acc_centroid_freq_z` float DEFAULT NULL COMMENT 'z加速度质心频率'," +
		"  `vi_acc_rms_freq_z` float DEFAULT NULL COMMENT 'z加速度均方根频率'," +
		"  `vi_acc_ms_freq_z` float DEFAULT NULL COMMENT 'z加速度均方频率'," +
		"  `vi_acc_var_freq_z` float DEFAULT NULL COMMENT 'z加速度方差频率'," +
		"  `vi_acc_std_freq_z` float DEFAULT NULL COMMENT 'z加速度标准差频率'," +
		"  `vi_velocity_max_z` float DEFAULT NULL COMMENT 'z速度峰值单位m/s'," +
		"  `vi_velocity_maxfreq_z` float DEFAULT NULL COMMENT 'z速度峰值频率 单位hz'," +
		"  `vi_velocity_rms_z` float DEFAULT NULL COMMENT 'z速度有效值'," +
		"  `vi_max_distance_z` float DEFAULT NULL COMMENT 'z最大距离值 单位mm'," +
		"  `vi_angle_z` float DEFAULT NULL COMMENT 'z安装角度'," +
		" `vi_temperature` float DEFAULT NULL COMMENT '温度'," +
		" `vi_voltage` float DEFAULT NULL COMMENT '电压'," +
		"   `status` tinyint DEFAULT NULL COMMENT '状态'," +
		"  `sampletime` bigint(20) unsigned DEFAULT NULL COMMENT 'sampletime'," +
		"  PRIMARY KEY (`id`) USING BTREE, UNIQUE KEY `device_sampletime` (`sampletime`,`device_no`) USING BTREE" +
		") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=COMPACT COMMENT='ae-vi数据表';"
	_, err = db.Exec(ctx, sql)
	if err != nil {
		return err
	}
	return
}

// DropAeVIParamDataTable ae-vi参数数据表删除
func (s *sDevice) DropAeVIParamDataTable(ctx context.Context, dbConn string, table string) (err error) {
	db := g.DB(dbConn)
	sql := " DROP TABLE IF EXISTS " + table
	_, err = db.Exec(ctx, sql)
	return
}

// CreateAeWaveTable 声发射波形表创建
func (s *sDevice) CreateAeWaveTable(ctx context.Context, dbConn string, table string) (err error) {
	db := g.DB(dbConn)
	sql := "CREATE TABLE IF NOT EXISTS `" + table + "` (" +
		"`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id'," +
		"`device_no` varchar(60) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT '' COMMENT '设备编号'," +
		"`sampletime` bigint unsigned DEFAULT '0' COMMENT '采集时间'," +
		"`created_at` datetime DEFAULT NULL COMMENT '创建时间'," +
		"`wave_type` tinyint unsigned DEFAULT NULL COMMENT '波形类型标志 0 时域 1 频域'," +
		"`flag` tinyint DEFAULT NULL COMMENT '标识 0本地 1oss'," +
		"`store_server` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '分布式服务器'," +
		"`bucket` varchar(40) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '桶'," +
		"`path` varchar(255) DEFAULT NULL COMMENT '路径'," +
		"`status` tinyint DEFAULT NULL COMMENT '状态0'," +
		"PRIMARY KEY (`id`) USING BTREE," +
		"KEY `sampletime` (`sampletime`) USING BTREE" +
		") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci ROW_FORMAT=COMPACT COMMENT='ae波形表';"
	_, err = db.Exec(ctx, sql)
	return
}

// DropAeWaveTable 声发射波形表删除
func (s *sDevice) DropAeWaveTable(ctx context.Context, dbConn string, table string) (err error) {
	db := g.DB(dbConn)
	sql := " DROP TABLE IF EXISTS " + table
	_, err = db.Exec(ctx, sql)
	return
}

// CreateViWaveTable 振动波形表创建
func (s *sDevice) CreateViWaveTable(ctx context.Context, dbConn string, table string) (err error) {
	db := g.DB(dbConn)
	sql := "CREATE TABLE IF NOT EXISTS `" + table + "` (" +
		"`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id'," +
		"`device_no` varchar(60) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT '' COMMENT '设备编号'," +
		"`sampletime` bigint unsigned DEFAULT '0' COMMENT '采集时间'," +
		"`created_at` datetime DEFAULT NULL COMMENT '创建时间'," +
		"`direction` tinyint unsigned DEFAULT NULL COMMENT '轴向【 0x 1y 2z】'," +
		"`wave_type` tinyint unsigned DEFAULT NULL COMMENT '波形类型标志 0 时域 1 频域'," +
		"`flag` tinyint DEFAULT NULL COMMENT '标识 0本地 1oss'," +
		"`store_server` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '分布式服务器'," +
		"`bucket` varchar(40) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '桶'," +
		"`path` varchar(255) DEFAULT NULL COMMENT '路径'," +
		"`status` tinyint DEFAULT NULL COMMENT '状态0'," +
		"PRIMARY KEY (`id`) USING BTREE," +
		"KEY `sampletime` (`sampletime`) USING BTREE" +
		") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci ROW_FORMAT=COMPACT COMMENT='vi波形表';"
	_, err = db.Exec(ctx, sql)
	return
}

// DropViWaveTable 振动波形表删除
func (s *sDevice) DropViWaveTable(ctx context.Context, dbConn string, table string) (err error) {
	db := g.DB(dbConn)
	sql := " DROP TABLE IF EXISTS " + table
	_, err = db.Exec(ctx, sql)
	return
}

// CreateAeTemplateWaveTable 声发射波形临时表创建
func (s *sDevice) CreateAeTemplateWaveTable(ctx context.Context, dbConn string, table string) (err error) {
	db := g.DB(dbConn)
	sql := "CREATE TABLE IF NOT EXISTS `" + table + "` (" +
		"`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id'," +
		"`device_no` varchar(60) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT '' COMMENT '设备编号'," +
		"`sampletime` bigint unsigned DEFAULT '0' COMMENT '采集时间'," +
		"`created_at` datetime DEFAULT NULL COMMENT '创建时间'," +
		"`wave_type` tinyint unsigned DEFAULT NULL COMMENT '波形类型标志 0 时域 1 频域'," +
		"`num` smallint DEFAULT NULL COMMENT '编号'," +
		"`wave_data` tinyblob COMMENT '分段波形 （既然分段则每一个波形少于255字节）'," +
		"PRIMARY KEY (`id`) USING BTREE," +
		"KEY `sec` (`sampletime`) USING BTREE" +
		") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci ROW_FORMAT=COMPACT COMMENT='波形临时表';"
	_, err = db.Exec(ctx, sql)
	return
}

// DropAeTemplateWaveTable 声发射波形临时表删除
func (s *sDevice) DropAeTemplateWaveTable(ctx context.Context, dbConn string, table string) (err error) {
	db := g.DB(dbConn)
	sql := " DROP TABLE IF EXISTS " + table
	_, err = db.Exec(ctx, sql)
	return
}

// CreateViTemplateWaveTable 振动波形临时表创建
func (s *sDevice) CreateViTemplateWaveTable(ctx context.Context, dbConn string, table string) (err error) {
	db := g.DB(dbConn)
	sql := "CREATE TABLE IF NOT EXISTS `" + table + "` (" +
		"`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id'," +
		"`device_no` varchar(60) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT '' COMMENT '设备编号'," +
		"`sampletime` bigint unsigned DEFAULT '0' COMMENT '采集时间'," +
		"`created_at` datetime DEFAULT NULL COMMENT '创建时间'," +
		"`direction` tinyint unsigned DEFAULT NULL COMMENT '轴向【 0x 1y 2z】'," +
		"`wave_type` tinyint unsigned DEFAULT NULL COMMENT '波形类型标志 0 时域 1 频域'," +
		"`num` smallint DEFAULT NULL COMMENT '编号'," +
		"`wave_data` tinyblob COMMENT '分段波形 （既然分段则每一个波形少于255字节）'," +
		"PRIMARY KEY (`id`) USING BTREE," +
		"KEY `sec` (`sampletime`) USING BTREE" +
		") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci ROW_FORMAT=COMPACT COMMENT='波形临时表';"
	_, err = db.Exec(ctx, sql)
	return
}

// DropViTemplateWaveTable 振动波形临时表删除
func (s *sDevice) DropViTemplateWaveTable(ctx context.Context, dbConn string, table string) (err error) {
	db := g.DB(dbConn)
	sql := " DROP TABLE IF EXISTS " + table
	_, err = db.Exec(ctx, sql)
	return
}
